package com.zz.string;

public class L9Solution {
    public boolean isPalindrome0(int x) {
        if(x < 0){
            return false;
        }
        String str = String.valueOf(x);
        StringBuilder builder = new StringBuilder(str);
        if(str.equals(builder.reverse())){
            return true;
        }
        return false;
    }
    public boolean isPalindrome(int x) {
        if(x < 0){
            return false;
        }
        String str = String.valueOf(x);
        StringBuilder sb = new StringBuilder(str);
        String reverse = sb.reverse().toString();
        for (int i = 0; i < str.length(); i++) {
            if(!reverse.substring(i, i + 1).equals(str.substring(i, i + 1))) {
                return false;
            }
        }
        return true;
    }

    public boolean isPalindrome2(int x) {
        if (x < 0 || (x % 10 == 0 && x != 0)) {
            return false;
        }
        String str = String.valueOf(x);
        int fast=1, last=str.length();
        while (fast < last){
            if(!str.substring(fast-1, fast++).equals(str.substring(last-1, last--))){
                return false;
            };

        }
        return true;
    }

    public static void main(String[] args) {
        boolean palindrome = new L9Solution().isPalindrome2(123431);
        System.out.println("palindrome = " + palindrome);
    }
}
